package com.marketlive.system.config.properties;

/*
(C) Copyright MarketLive. 2006. All rights reserved.
MarketLive is a trademark of MarketLive, Inc.
Warning: This computer program is protected by copyright law and international treaties.
Unauthorized reproduction or distribution of this program, or any portion of it, may result
in severe civil and criminal penalties, and will be prosecuted to the maximum extent
possible under the law.
*/

import java.util.Properties;
import java.util.ArrayList;
import com.marketlive.system.config.ConfigurationBranch;

/**
 * Loads a configuration into java.util.Properties.
 */
public class PropertiesLoader extends Properties {

    /**
     * Loads the given <code>Properties</code> into the starting branch. 
     * @param startingBranch the <code>ConfigurationBranch</code> to use as starting point
     * @param props the <code>Properties</code> to load
     */
    public static void loadProperties(ConfigurationBranch startingBranch, Properties props) {

        // load the properties
        ArrayList keys = new ArrayList();
        startingBranch.getLeafNames(keys,null);

        for (int i=0; i<keys.size(); i++) {
            String name = (String) keys.get(i);
            String value = startingBranch.getAsString(name);
            props.put(name,value);
        }
    }
}